﻿using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WeifenLuo.WinFormsUI.Docking;
using T3K.SketchEditor.Core;


namespace T3K.SketchEditor.Forms {
    public partial class OutputForm : BaseForm {

        public OutputForm(string windowName) : base (windowName) {
            InitializeComponent();
            this.txtOutput.DoubleClick += new EventHandler(txtOutput_DoubleClick);
        }

        void txtOutput_DoubleClick(object sender, EventArgs e) {
            int currentLine = this.CurrentLine;
            if (currentLine < this.txtOutput.Lines.Length) {
                EditorEventArgs args = new EditorEventArgs(GetWindowEventName("DoubleClick"));
                args["Line"] = txtOutput.Lines[CurrentLine];
                Editor.FireEvent(this, args);
            }
        }

        private int CurrentColumn {
            get { return txtOutput.SelectionStart - txtOutput.GetFirstCharIndexOfCurrentLine(); }
        }

        private int CurrentLine {
            get { return txtOutput.GetLineFromCharIndex(txtOutput.SelectionStart); }
        }

        private void OutputForm_Load(object sender, EventArgs e) {
            
        }

        [Command("WriteLine")]
        public void OutputText(object sender, CommandArgs args) {
            string line = args["Out"].ToString();
            this.txtOutput.Text += string.Format("{0}{1}", line, Environment.NewLine);
            this.txtOutput.ScrollBars = ScrollBars.Both;
            this.txtOutput.SelectionStart = this.txtOutput.Text.Length - 1;
            this.txtOutput.SelectionLength = 0;
            this.txtOutput.ScrollToCaret();
        }

    }
}
